rm(list = ls())

library(tidyverse)
library(lfe)

## Load MP data

dat <- readRDS('data/mp_data.rds')  %>%
  filter(vote_abstain_no_show == 0) %>%
  filter(elecper != 8) %>%
  filter(!is.na(location_33_39_ags)) %>%
  left_join(readRDS("data/qje_dat_clean.rds"), by = c('location_33_39_ags' = 'ags')) %>%
  mutate(share_jewish_33_rl = ifelse(!is.na(location_33_39_ags) & is.na(share_jewish_33_rl), 0, share_jewish_33_rl)) ## 0s are not recorded in QJE Data 

## 

experience_covars <- c('nsdap_member', 
                       'share_jewish_33_rl', 
                       'syn_attacked_33_39',
                       'rel_cath',
                       'veteran_ww1',
                       'veteran_ww2', 
                       'capture_ww2',
                       'soviet_capture',
                       'exile_repressed_combined', 
                       'resistance_member')

covars <- c('year_birth', 'gender', 'mandate', 'dualcand', 'closeness_district_categ')

#### 

m1 <-  paste('vote_yes', '~', paste(experience_covars[2:3], collapse = "+"),'', ' | elecper  | 0 | ags_cluster_33_39')
m2 <-  paste('vote_yes', '~', paste(experience_covars[2:3], collapse = "+"),'', ' | elecper + party_fe | 0 | ags_cluster_33_39')
m3 <-  paste('vote_yes', '~', paste(experience_covars[2:3], collapse = "+"),'', ' | elecper + party_fe + state_id | 0 | ags_cluster_33_39')
m4 <-  paste('vote_yes', '~', paste(experience_covars, collapse = "+"),'+', paste(covars, collapse = "+"), ' | elecper  | 0 | ags_cluster_33_39')
m5 <-  paste('vote_yes', '~', paste(experience_covars, collapse = "+"),'+', paste(covars, collapse = "+"), ' | elecper + party_fe | 0 | ags_cluster_33_39')
m6 <-  paste('vote_yes', '~', paste(experience_covars, collapse = "+"),'+', paste(covars, collapse = "+"), ' | elecper + party_fe + state_id | 0 | ags_cluster_33_39')

mlist <- list(m1, m2, m3, m4, m5, m6)

## Estimate 

mlist_res <- lapply(mlist, function(m){
  
  m_est <- felm(m %>% as.formula(),
                data = dat)
  
  return(m_est)
  
})

## To Table 

stargazer::stargazer(mlist_res, 
                     style  = 'ajps',
                     keep = c('share_jewish_33_rl', 'syn_attacked_33_39'),
                     covariate.labels = c('Jewish pop. share (in %)', 'Synagogue: attacked'))


